package com.example.sql_2_code_demo.service.impl;

import com.example.sql_2_code_demo.entity.OrderUrgingPayment;
import com.example.sql_2_code_demo.dao.OrderUrgingPaymentDao;
import com.example.sql_2_code_demo.service.OrderUrgingPaymentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单催缴记录表(OrderUrgingPayment)表服务实现类
 *
 * @author makejava
 * @since 2022-10-09 10:01:38
 */
@Service("orderUrgingPaymentService")
public class OrderUrgingPaymentServiceImpl implements OrderUrgingPaymentService {
    @Resource
    private OrderUrgingPaymentDao orderUrgingPaymentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrderUrgingPayment queryById(Long id) {
        return this.orderUrgingPaymentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderUrgingPayment 筛选条件
     * @param pageRequest        分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderUrgingPayment> queryByPage(OrderUrgingPayment orderUrgingPayment, PageRequest pageRequest) {
        long total = this.orderUrgingPaymentDao.count(orderUrgingPayment);
        return new PageImpl<>(this.orderUrgingPaymentDao.queryAllByLimit(orderUrgingPayment, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderUrgingPayment 实例对象
     * @return 实例对象
     */
    @Override
    public OrderUrgingPayment insert(OrderUrgingPayment orderUrgingPayment) {
        this.orderUrgingPaymentDao.insert(orderUrgingPayment);
        return orderUrgingPayment;
    }

    /**
     * 修改数据
     *
     * @param orderUrgingPayment 实例对象
     * @return 实例对象
     */
    @Override
    public OrderUrgingPayment update(OrderUrgingPayment orderUrgingPayment) {
        this.orderUrgingPaymentDao.update(orderUrgingPayment);
        return this.queryById(orderUrgingPayment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.orderUrgingPaymentDao.deleteById(id) > 0;
    }
}
